package com.bulletelc.apollopre.module.main.center.afterSale;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.ServiceOrderBean;
import com.bulletelc.apollopre.framework.MVPBaseActivity;
import com.bulletelc.apollopre.utils.ToastUtil;
import com.bulletelc.apollopre.widget.FoolBar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by CX on 2018/1/26.
 */

public class ServiceOrderListActivity extends MVPBaseActivity<ServiceOrderContract.View, ServiceOrderPresenter> implements
       ServiceOrderContract.View, FoolBar.ClickCallback {

    private RelativeLayout rlNoContent;
    private FoolBar flBar;
    private ListView listView;
    private List<ServiceOrderBean> sobList;
    private ServiceOrderAdapter adapter;

    @Override
    public int getLayoutRes() {
        return R.layout.service_order_list_activity;
    }

    @Override
    public void assignViews() {
        flBar = findView(R.id.flBar);
        flBar.setTitle(this.getResources().getString(R.string.center_service));
        rlNoContent = findView(R.id.rlNoContent);
        listView = findView(R.id.lv_service);
    }

    @Override
    public void setListener() {
        flBar.setClickCallback(this);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        sobList = new ArrayList<>();
        adapter = new ServiceOrderAdapter(this, sobList);
        listView.setAdapter(adapter);
        presenter.getServiceOrderList();
    }

    @Override
    protected ServiceOrderPresenter createPresenter() {
        return new ServiceOrderPresenter();
    }

    @Override
    public void onSuccessServiceOrderList(List<ServiceOrderBean> serviceOrders) {
        if (serviceOrders != null && serviceOrders.size() > 0) {
            rlNoContent.setVisibility(View.GONE);
            sobList.clear();
            sobList.addAll(serviceOrders);
            adapter.notifyDataSetChanged();
            listView.setVisibility(View.VISIBLE);
        } else {
            rlNoContent.setVisibility(View.VISIBLE);
            listView.setVisibility(View.GONE);
        }
    }

    @Override
    public void onFailServiceOrderList(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onErrorServiceOrderList(String msg) {
        ToastUtil.showLongToast(this,R.string.network_msg);
    }

    @Override
    public void onLeftClick() {
        finish();
    }

    @Override
    public void onRightClick() {

    }
}
